﻿
@{
    ViewData["Title"] = "TestImg";
    Layout = "~/Views/Shared/_Layout_Content.cshtml";
}
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="~/css/bootstrap-fileinput.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="~/js/bootstrap-fileinput.js"></script>
<body>
    <form>
        <div>
            <div class="modal-header">
                <h4 class="modal-title" id="modalShow">[请选择xml/docx]文件</h4>
            </div>
            <div class="modal-body">
                <input type="file" name="model_file" id="model_file" multiple class="file-loading" />
            </div>
        </div>
    </form>
    <script type="text/javascript">
        $(function () {
            var control = $("#model_file");
            var uploadrul = "/FileUpload/OnPostUpload?handler=Upload";
            var upObj = {
                language: 'zh', //设置语言
                uploadUrl: uploadrul, //上传的地址
                uploadExtraData: { "savepath": "/bootstrap-fileinput-master/examples/" },//上传至服务器的参数，非常重要
                allowedFileExtensions: ['xml', 'docx', 'jpg', 'png', 'gif', 'rar', 'doc'],//接收的文件后缀
                showUpload: true, //显示批量上传按钮
                showCaption: false,//是否显示标题
                browseClass: "btn btn-primary", //按钮样式
                dropZoneEnabled: true,//是否显示拖拽区域
                maxFileSize: 4096,//单位为kb，如果为0表示不限制文件大小
                minFileCount: 0,
                maxFileCount: 10,
                msgSizeTooLarge: " \"{name}\" 大小为({size} KB) 最大文件大小为 {maxSize} KB.请重新上传!",//文件的实际大小有些许偏差
                enctype: 'multipart/form-data',
                validateInitialCount: true,
                previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
                allowedPreviewTypes: ['image']//能够预览的文件类型，如果不限制。文件预览时可能很慢
            };
            $('#modalShow').html("[请选择" + upObj.allowedFileExtensions + "]文件");
            control.fileinput(upObj);

            //导入文件上传成功之后的事件
            $("#model_file").on("fileuploaded", function (event, data, previewId, index) {
                alert("aaa");
            });
            //导入文件上传失败之后的事件
            $('#model_file').on('fileuploaderror', function (event, data, msg) {
                alert("aaa");
            });
        });
    </script>
</body>